<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="crm.control.ProductControl" %>
<%@ page import="crm.model.Product_model" %>
<%@ page import="crm.util.ParamUtil"%>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Calendar" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>    
    <title>My JSP 'product_model_add_do.jsp' starting page</title>
  </head> 
  <body>
         <%
             request.setCharacterEncoding("UTF-8");
             Product_model productModel = new Product_model();
             
             String model_name=ParamUtil.getString(request,"product_model_name");
             productModel.setModel_name(model_name);
             
             String model_number=ParamUtil.getString(request,"product_model_number");
             productModel.setModel_number(model_number);
             
             int system_product_id=ParamUtil.getInt(request,"product_model_system_product_id",1);
             productModel.setSystem_product_id(system_product_id);
             
             String develope_depart=ParamUtil.getString(request,"product_model_develope_depart","");
             productModel.setDevelope_depart(develope_depart);
             
             String developer=ParamUtil.getString(request,"product_model_developer","");
             productModel.setDeveloper(developer);
             
             String price=ParamUtil.getString(request,"product_model_price","");
             productModel.setPrice(price);
             
             String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
             String create_time=ParamUtil.getString(request,"product_model_create_time",date);
             productModel.setCreate_time(create_time);
             
             String description=ParamUtil.getString(request,"product_model_description","无");
             productModel.setDescription(description);
             
             
           if(productModel.getModel_number()==null){ 
            %>
            <script type="text/javascript">
            window.alert("系统编号不能为空");
            window.location.href="product_model_add.jsp";
            </script>
            <%}else if(ProductControl.modelNameIsExist(model_name)){
            %>
            <script type="text/javascript">
            window.alert("模块名称重复！添加失败");
            window.location.href="product_model_add.jsp";
            </script>   
            <%}else if(ProductControl.modelNumberIsExist(model_number)){
            %>
            <script type="text/javascript">
            window.alert("编号重复！添加失败");
            window.location.href="product_model_add.jsp";
            </script>
            <%}else if(ProductControl.addProductModel(productModel)){
            %>
           <script type="text/javascript">
if (window.confirm("添加商品成功，是否继续添加？"))
	window.location.href = "product_model_add.jsp";
else
	window.location.href = "product_model.jsp";
           </script>
           <%
           }
           %>
  </body>
</html>
